package com.returnsoft.resource.service;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import com.returnsoft.resource.dto.EducationLevelDto;
import com.returnsoft.resource.eao.EducationLevelEao;
import com.returnsoft.resource.entity.EducationLevel;
import com.returnsoft.resource.exception.ConversionExcepcion;
import com.returnsoft.resource.exception.EaoExcepcion;
import com.returnsoft.resource.exception.RecruitmentException;
import com.returnsoft.resource.util.Conversion;

/**
 * Session Bean implementation class EducationLevelBean
 */
@Stateless
@LocalBean
public class EducationLevelBean implements EducationLevelInterface {
	
	@EJB
	private EducationLevelEao eao;
	@EJB
	private Conversion conv;

    /**
     * Default constructor. 
     */
    public EducationLevelBean() {
        // TODO Auto-generated constructor stub
    }
    
    @Override
   	public List<EducationLevelDto> findAll() throws RecruitmentException {
   		try {
   			List<EducationLevel> entities = eao.findAll();
   			List<EducationLevelDto> dtos = new ArrayList<EducationLevelDto>();
   			for (EducationLevel entity : entities) {
   				EducationLevelDto dto = conv.fromEducationLevel(entity);
   				dtos.add(dto);
   			}
   			return dtos;
   		} catch (EaoExcepcion e) {
   			throw new RecruitmentException(e.getMessage());
   		} catch (ConversionExcepcion e) {
   			throw new RecruitmentException(e.getMessage());
   		} catch (Exception e) {
   			e.printStackTrace();
   			throw new RecruitmentException(e.getMessage());
   		}
   	}

}
